<?php
class DApplication extends DModule
{
	public function __construct(){
		parent::__construct();
		DXPHP::setApplication($this);
	}
	
	public function run() {
		$controller = $this->load_controller();
		if (method_exists($controller, ROUTE_A)) {
			if (preg_match('/^[_]/i', ROUTE_A)) {
				exit('You are visiting the action is to protect the private action');
			} else {
				call_user_func(array($controller, ROUTE_A));
			}
		} else {
			exit('Action does not exist.');
		}
	}
	
	private function load_controller($filename = '', $m = '') {
		if (empty($filename)) $filename = ROUTE_C;
		if (empty($m)) $m = ROUTE_M;
		$file = MODULE_PATH.$m.'/'.CONTROL_DIR.'/'.$filename.'.php';
		if (is_file($file)) {
			$classname = $filename;
			include $file;
			return new $classname;
		} else {
			exit(ROUTE_C.' not exist.');
		}
	}
}
?>